<template>
    <div>
        <el-form-item>
            <el-button type="primary" icon="el-icon-error" @click="clearSearchForm">
                重置
            </el-button>
            <el-button type="primary" icon="el-icon-search" @click="fetchList">
                查询
            </el-button>
            <el-button v-if="addFlag" type="primary" @click="addFun">新增</el-button>
        </el-form-item>
        <el-dropdown v-if="exportFlag">
            <el-button type="primary">
                导入导出<i class="el-icon-arrow-down el-icon--right"/>
            </el-button>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                    <el-button
                            type="text"
                            icon="el-icon-download"
                            @click="downloadTemplate"
                    >
                        模板下载
                    </el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                    <el-button
                            type="text"
                            icon="el-icon-upload2"
                    >
                        导入数据
                    </el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                    <el-button
                            type="text"
                            icon="el-icon-download"
                            @click="exportMethod"
                    >
                        导出数据
                    </el-button>
                </el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
</template>
<script>
    export default {
        name: 'SearchButtons',
        props: {
            exportFlag: {
                type: Boolean,
                default: false
            },
            fetchData: {
                type: Function
            },
            templateUrl: {
                type: String,
                default: null
            },
            exportExcel: {
                type: Function,
                default: null
            },
            addFun: {
                type: Function,
                default: null
            },
            addFlag: {
                type: Boolean,
                default: true
            }
        },
        methods: {
            clearSearchForm() {
                this.$parent.$parent.searchForm = {}
                this.fetchList()
            },
            fetchList() {
                this.fetchData()
            },
            downloadTemplate() {
                window.location.href = this.templateUrl
            },
            exportMethod() {
                this.export2Excel()
            }
        }
    }
</script>
